package _2_abstract_factory

//RuleConfig 规则配置
type RuleConfig struct {
	fileType string
}

func (r *RuleConfig) String() string {
	return r.fileType
}

// RuleFileParse 文件解析接口
type RuleFileParse interface {
	parse(filePath string) RuleConfig
}

// RuleFileWriter 规则文件写入器
type RuleFileWriter interface {
	write(filePath, content string) error
}

// RuleFileHandlerFactory 抽象工厂 获取一组对应的实现
type RuleFileHandlerFactory interface {
	GetRuleFileParse() RuleFileParse
	GetRuleFileWrite() RuleFileWriter
}

// jsonFileParse 解析json文件
type jsonFileParse struct {
}

func (j *jsonFileParse) parse(file string) RuleConfig {
	//parse json context
	return RuleConfig{fileType: "json"}
}

// xmlFileParse 解析xml文件
type xmlFileParse struct {
}

func (x *xmlFileParse) parse(file string) RuleConfig {
	//parse xml context
	return RuleConfig{fileType: "xml"}
}

// propertiesFileParse 解析 properties 文件
type propertiesFileParse struct {
}

func (p *propertiesFileParse) parse(file string) RuleConfig {
	//parse properties context
	return RuleConfig{fileType: "properties"}
}

// jsonFileWrite 写入json内容配置
type jsonFileWrite struct {
}

func (j *jsonFileWrite) write(file, content string) error {
	//write ...
	return nil
}

// xmlFileParse 解析xml文件
type xmlFileWrite struct {
}

func (x *xmlFileWrite) write(file, content string) error {
	//Write...
	return nil
}

// propertiesFileWrite 解析 properties 文件
type propertiesFileWrite struct {
}

func (p *propertiesFileWrite) write(file, content string) error {
	//Write...
	return nil
}

// JsonRuleFileHandlerFactory json文件格式的工厂
type JsonRuleFileHandlerFactory struct {
}

func (j *JsonRuleFileHandlerFactory) GetRuleFileParse() RuleFileParse {
	return &jsonFileParse{}
}

func (j *JsonRuleFileHandlerFactory) GetRuleFileWrite() RuleFileWriter {
	return &jsonFileWrite{}
}

// XmlRuleFileHandlerFactory xml文件格式的工厂
type XmlRuleFileHandlerFactory struct {
}

func (x *XmlRuleFileHandlerFactory) GetRuleFileParse() RuleFileParse {
	return &xmlFileParse{}
}

func (x *XmlRuleFileHandlerFactory) GetRuleFileWrite() RuleFileWriter {
	return &xmlFileWrite{}
}

// PropertiesRuleFileHandlerFactory properties文件格式的工厂
type PropertiesRuleFileHandlerFactory struct {
}

func (p *PropertiesRuleFileHandlerFactory) GetRuleFileParse() RuleFileParse {
	return &propertiesFileParse{}
}

func (p *PropertiesRuleFileHandlerFactory) GetRuleFileWrite() RuleFileWriter {
	return &propertiesFileWrite{}
}
